//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "SabrVolSurface.h"
using namespace Cephei::QL::Experimental::Volatility;
#include <gen/QL/Experimental/Volatility/BlackAtmVolCurve.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Indexes/InterestRateIndex.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Quote.h>
#include <gen/QL/Termstructures/Volatility/SmileSection.h>
#include <gen/QL/Experimental/Volatility/InterestRateVolSurface.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures::Volatility;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Volatility::CSabrVolSurface::CSabrVolSurface (Cephei::QL::Indexes::IInterestRateIndex^ index, Cephei::QL::Experimental::Volatility::IBlackAtmVolCurve^ atmCurve, Cephei::Core::IVector<Cephei::QL::Times::IPeriod^>^ optionTenors, Cephei::Core::IVector<Double>^ atmRateSpreads, Cephei::Core::IMatrix<Cephei::QL::IQuote^>^ volSpreads) : CInterestRateVolSurface(CSabrVolSurface::typeid)
{
    CInterestRateIndex^ _Cindex;
    CBlackAtmVolCurve^ _CatmCurve;
    try
    {
#ifdef HANDLE
        _phSabrVolSurface = NULL;
#endif
        _Cindex = safe_cast<CInterestRateIndex^> (index);
        _Cindex->Lock();
        boost::shared_ptr<QuantLib::InterestRateIndex>& _index = static_cast<boost::shared_ptr<QuantLib::InterestRateIndex>&> (_Cindex->GetShared ()); 
        _CatmCurve = safe_cast<CBlackAtmVolCurve^> (atmCurve);
        _CatmCurve->Lock();
        Handle<QuantLib::BlackAtmVolCurve>& _atmCurve = static_cast<Handle<QuantLib::BlackAtmVolCurve>&> (_CatmCurve->GetHandle ()); 
        optionTenors ->Lock ();
        INativeVector<Cephei::QL::Times::IPeriod^>^ _NCIoptionTenors = optionTenors->getFeature (NativeFeature::Value);
        CPeriodVector^ _NCoptionTenors = safe_cast<CPeriodVector^>(_NCIoptionTenors);
        std::vector<QuantLib::Period>& _optionTenors = static_cast<std::vector<QuantLib::Period>&> (_NCoptionTenors->GetReference ());
        atmRateSpreads->Lock();
        INativeVector<Double>^ _NCIatmRateSpreads = atmRateSpreads->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCatmRateSpreads = safe_cast<CDoubleVector^>(_NCIatmRateSpreads);
        std::vector<QuantLib::Spread>& _atmRateSpreads = static_cast<std::vector<QuantLib::Spread>&> (_NCatmRateSpreads->GetReference ());
        volSpreads ->Lock ();
        INativeMatrix<Cephei::QL::IQuote^>^ _NCIvolSpreads = volSpreads->getFeature (NativeFeature::Handle);
        CQuoteMatrix^ _NCvolSpreads = safe_cast<CQuoteMatrix^>(_NCIvolSpreads);
        std::vector<std::vector<Handle<QuantLib::Quote> > >& _volSpreads = static_cast<std::vector<std::vector<Handle<QuantLib::Quote> > >&> (_NCvolSpreads->GetHandle ());
        _ppSabrVolSurface = new boost::shared_ptr<QuantLib::SabrVolSurface> (new QuantLib::SabrVolSurface ( _index,  _atmCurve,  _optionTenors,  _atmRateSpreads,  _volSpreads ));
        SetInterestRateVolSurface (boost::dynamic_pointer_cast<QuantLib::InterestRateVolSurface> (*_ppSabrVolSurface));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cindex != nullptr) _Cindex->Unlock();
        if (_CatmCurve != nullptr) _CatmCurve->Unlock();
        if (optionTenors != nullptr) optionTenors->Unlock();    //not optional
        if (atmRateSpreads != nullptr) atmRateSpreads->Unlock();    //not optional
        if (volSpreads != nullptr) volSpreads->Unlock();    //not optional
    }
}
Cephei::QL::Experimental::Volatility::CSabrVolSurface::CSabrVolSurface (boost::shared_ptr<QuantLib::SabrVolSurface>& childNative, Object^ owner) : CInterestRateVolSurface(CSabrVolSurface::typeid)
{
#ifdef HANDLE
	_phSabrVolSurface = NULL;
#endif
	_ppSabrVolSurface = &childNative;
    _ppInterestRateVolSurface = new boost::shared_ptr<QuantLib::InterestRateVolSurface> (boost::dynamic_pointer_cast<QuantLib::InterestRateVolSurface> (*_ppSabrVolSurface));
}
Cephei::QL::Experimental::Volatility::CSabrVolSurface::CSabrVolSurface (QuantLib::SabrVolSurface& childNative, Object^ owner) : CInterestRateVolSurface(CSabrVolSurface::typeid)
{
#ifdef HANDLE
	_phSabrVolSurface = NULL;
#endif
	_ppSabrVolSurface = new boost::shared_ptr<QuantLib::SabrVolSurface> (&childNative);
    _ppInterestRateVolSurface = new boost::shared_ptr<QuantLib::InterestRateVolSurface> (boost::dynamic_pointer_cast<QuantLib::InterestRateVolSurface> (*_ppSabrVolSurface));
    _SabrVolSurfaceOwner = owner;
    _InterestRateVolSurfaceOwner = owner;
}

Cephei::QL::Experimental::Volatility::CSabrVolSurface::CSabrVolSurface (CSabrVolSurface^ copy) : CInterestRateVolSurface(CSabrVolSurface::typeid)
{
#ifdef HANDLE
	_phSabrVolSurface = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppSabrVolSurface = new boost::shared_ptr<QuantLib::SabrVolSurface> (copy->GetShared());
        _ppInterestRateVolSurface = new boost::shared_ptr<QuantLib::InterestRateVolSurface> (boost::dynamic_pointer_cast<QuantLib::InterestRateVolSurface> (*_ppSabrVolSurface));
    }
}
Cephei::QL::Experimental::Volatility::CSabrVolSurface::CSabrVolSurface (PLATFORM::Type^ t) : CInterestRateVolSurface(CSabrVolSurface::typeid)
{
#ifdef HANDLE
	_phSabrVolSurface = NULL;
#endif
	if (!t->IsSubclassOf(CSabrVolSurface::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Volatility::CSabrVolSurface::CSabrVolSurface (QuantLib::Handle<QuantLib::SabrVolSurface>& childNative, Object^ owner)  : CInterestRateVolSurface(CSabrVolSurface::typeid)
{
	_phSabrVolSurface = &childNative;
	_ppSabrVolSurface = &static_cast<boost::shared_ptr<QuantLib::SabrVolSurface>>(childNative.currentLink());
    _ppInterestRateVolSurface = new boost::shared_ptr<QuantLib::InterestRateVolSurface> (boost::dynamic_pointer_cast<QuantLib::InterestRateVolSurface> (*_ppSabrVolSurface));
    _SabrVolSurfaceOwner = owner;
}
Cephei::QL::Experimental::Volatility::CSabrVolSurface::CSabrVolSurface (QuantLib::Handle<QuantLib::SabrVolSurface> childNative)  : CInterestRateVolSurface(CSabrVolSurface::typeid)
{
	_phSabrVolSurface = &childNative;
	_ppSabrVolSurface = &static_cast<boost::shared_ptr<QuantLib::SabrVolSurface>>(childNative.currentLink());
    _ppInterestRateVolSurface = new boost::shared_ptr<QuantLib::InterestRateVolSurface> (boost::dynamic_pointer_cast<QuantLib::InterestRateVolSurface> (*_ppSabrVolSurface));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Volatility::CSabrVolSurface::CSabrVolSurface (QuantLib::SabrVolSurface childNative)  : CInterestRateVolSurface(CSabrVolSurface::typeid)
{
#ifdef HANDLE
	_phSabrVolSurface = NULL;
#endif
	_ppSabrVolSurface = new boost::shared_ptr<QuantLib::SabrVolSurface> (new QuantLib::SabrVolSurface (childNative));
    _ppInterestRateVolSurface = new boost::shared_ptr<QuantLib::InterestRateVolSurface> (boost::dynamic_pointer_cast<QuantLib::InterestRateVolSurface> (*_ppSabrVolSurface));
}
#endif

Cephei::QL::Experimental::Volatility::CSabrVolSurface::~CSabrVolSurface ()
{
    if (_ppSabrVolSurface != NULL)
    {
	    delete _ppSabrVolSurface;
        _ppSabrVolSurface = NULL;
    }
}
Cephei::QL::Experimental::Volatility::CSabrVolSurface::!CSabrVolSurface ()
{
    if (_ppSabrVolSurface != NULL)
    {
	    delete _ppSabrVolSurface;
    }
}
QuantLib::SabrVolSurface& Cephei::QL::Experimental::Volatility::CSabrVolSurface::GetReference ()
{
    if (_ppSabrVolSurface == NULL) throw REFNEW NativeNullException ();
	return **_ppSabrVolSurface;
}
boost::shared_ptr<QuantLib::SabrVolSurface>& Cephei::QL::Experimental::Volatility::CSabrVolSurface::GetShared ()
{
    if (_ppSabrVolSurface == NULL) throw REFNEW NativeNullException ();
	return *_ppSabrVolSurface;
}
QuantLib::SabrVolSurface* Cephei::QL::Experimental::Volatility::CSabrVolSurface::GetPointer ()
{
    if (_ppSabrVolSurface == NULL) throw REFNEW NativeNullException ();
	return &**_ppSabrVolSurface;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::SabrVolSurface>& Cephei::QL::Experimental::Volatility::CSabrVolSurface::GetHandle ()
{
	if (_phSabrVolSurface == NULL)
	{
		_phSabrVolSurface = new Handle<QuantLib::SabrVolSurface> (*_ppSabrVolSurface);
	}
	return *_phSabrVolSurface;
}
#endif
bool Cephei::QL::Experimental::Volatility::CSabrVolSurface::HasNative () 
{
	return (_ppSabrVolSurface != NULL);
}

Cephei::QL::Experimental::Volatility::IBlackAtmVolCurve^ Cephei::QL::Experimental::Volatility::CSabrVolSurface::AtmCurve::get ()
{
    try
    {
    	Handle<QuantLib::BlackAtmVolCurve>& _rv = (Handle<QuantLib::BlackAtmVolCurve>&)(*_ppSabrVolSurface)->atmCurve ( );   
        Cephei::QL::Experimental::Volatility::CBlackAtmVolCurve^ _nrv = REFNEW Cephei::QL::Experimental::Volatility::CBlackAtmVolCurve (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ICalendar^ Cephei::QL::Experimental::Volatility::CSabrVolSurface::Calendar::get ()
{
    try
    {
    	QuantLib::Calendar _rv = (QuantLib::Calendar)(*_ppSabrVolSurface)->calendar ( );   
        Cephei::QL::Times::CCalendar^ _nrv = REFNEW Cephei::QL::Times::CCalendar (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IDayCounter^ Cephei::QL::Experimental::Volatility::CSabrVolSurface::DayCounter::get ()
{
    try
    {
    	QuantLib::DayCounter _rv = (QuantLib::DayCounter)(*_ppSabrVolSurface)->dayCounter ( );   
        Cephei::QL::Times::CDayCounter^ _nrv = REFNEW Cephei::QL::Times::CDayCounter (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Experimental::Volatility::CSabrVolSurface::MaxDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSabrVolSurface)->maxDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CSabrVolSurface::MaxStrike::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrVolSurface)->maxStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CSabrVolSurface::MaxTime::get ()
{
    try
    {
    	QuantLib::Time _rv = (QuantLib::Time)(*_ppSabrVolSurface)->maxTime ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CSabrVolSurface::MinStrike::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrVolSurface)->minStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Experimental::Volatility::CSabrVolSurface::ReferenceDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSabrVolSurface)->referenceDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt32 Cephei::QL::Experimental::Volatility::CSabrVolSurface::SettlementDays::get ()
{
    try
    {
    	QuantLib::Natural _rv = (QuantLib::Natural)(*_ppSabrVolSurface)->settlementDays ( );   
        UInt32 _nrv = (UInt32)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Termstructures::Volatility::ISmileSection^ Cephei::QL::Experimental::Volatility::CSabrVolSurface::SmileSectionImpl (Double t)
{
    try
    {
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t); //a
    	boost::shared_ptr<QuantLib::SmileSection> _rv = (boost::shared_ptr<QuantLib::SmileSection>)(*_ppSabrVolSurface)->smileSectionImpl ( _t );   
        Cephei::QL::Termstructures::Volatility::CSmileSection^ _nrv = REFNEW Cephei::QL::Termstructures::Volatility::CSmileSection (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Experimental::Volatility::CSabrVolSurface::VolatilitySpreads (DateTime d)
{
    try
    {
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d); //a
    	std::vector<QuantLib::Volatility> _rv = (std::vector<QuantLib::Volatility>)(*_ppSabrVolSurface)->volatilitySpreads ( _d );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Experimental::Volatility::CSabrVolSurface::VolatilitySpreads (Cephei::QL::Times::IPeriod^ prm1)
{
    CPeriod^ _Cprm1;
    try
    {
        _Cprm1 = safe_cast<CPeriod^> (prm1);
        _Cprm1->Lock();
        QuantLib::Period& _prm1 = static_cast<QuantLib::Period&> (_Cprm1->GetReference ()); 
    	std::vector<QuantLib::Volatility> _rv = (std::vector<QuantLib::Volatility>)(*_ppSabrVolSurface)->volatilitySpreads ( _prm1 );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cprm1 != nullptr) _Cprm1->Unlock();
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Volatility::ISabrVolSurface^ Cephei::QL::Experimental::Volatility::CSabrVolSurface_Factory::Create (Cephei::QL::Indexes::IInterestRateIndex^ index, Cephei::QL::Experimental::Volatility::IBlackAtmVolCurve^ atmCurve, Cephei::Core::IVector<Cephei::QL::Times::IPeriod^>^ optionTenors, Cephei::Core::IVector<Double>^ atmRateSpreads, Cephei::Core::IMatrix<Cephei::QL::IQuote^>^ volSpreads)
{
    return REFNEW CSabrVolSurface ( index,  atmCurve,  optionTenors,  atmRateSpreads,  volSpreads);
}
